home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
13288
/
13288.xpi
/
content
/
overlay.js
< prev
next >
Wrap
Text File
|
2010-01-24
|
62KB
|
1,393 lines
var stmM = {
gPrefs: Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.stm."),
gFFContentAreaClick: null, /* firefox original ContentAreaClick function */
TME_TOOLBARBUTTON: "stm-togglebutton",
gWinLoaded: false,
gBlockingOn: false,
gOldScrollBoxWidth: -1,
gFFVersion: Application.version.substr(0, 3), //Firefox version, such as 3.5, 3.6
closeByKey: false, //working with closeLeftTabs/closeRightTabs
openedTabs: new Array(), //working with lastSelectedTab
arrayTop: 0,
onLoad: function() {
this.addTabMenu(); // add tab context menu
this.changeHotkey("k.pageLock", this.gPrefs.getCharPref("pagelock.hotkey")); // load hotkey
this.changeHotkey("k.block", this.gPrefs.getCharPref("block.hotkey")); // load hotkey
this.changeHotkey("k.hideFF", this.gPrefs.getCharPref("bosskey.hidekey")); // load hotkey
this.register(); // preference register
this.enableNewTabPosition(); //set tab parent and children
this.doEvalAtStart(); //execute removeBlankTab() in openUILinkIn()
//first run
this.openURLBarInNewTab(this.gPrefs.getBoolPref("openURLBarInNewTab"));
this.enableOpenBHSInNewTab(this.gPrefs.getBoolPref("openBHSInNewTab"));
this.chgTabBarPosition(this.gPrefs.getIntPref("tabBarPosition"));
this.chgNewTabBtnPos(this.gPrefs.getIntPref("newTabBtnPos"));
this.enableMultiTabRows(this.gPrefs.getBoolPref("tabBarMultiRows"));
this.showStatusbarIcon(this.gPrefs.getBoolPref("statusbarIcon"));
this.showToolMenuItem(this.gPrefs.getBoolPref("toolMenuItem"));
this.enableDoubleClickListener(this.gPrefs.getBoolPref("doubleClickRemoveTab"));
this.showCloseRightTabsMenu(this.gPrefs.getBoolPref("showCloseRightTabs"));
this.showCloseLeftTabsMenu(this.gPrefs.getBoolPref("showCloseLeftTabs"));
this.enableFocusAfterCloseTab(this.gPrefs.getIntPref("focusAfterCloseTab"));
this.showHistoryTopMenu(this.gPrefs.getBoolPref("showHistoryMenu"));
this.chgHistoryBtnShape(this.gPrefs.getIntPref("historyButtonShape"));
this.chgURLBarListFontSize(this.gPrefs.getIntPref("urlbarListFontSize"));
this.enablePL(this.gPrefs.getBoolPref("pagelock.enable"));
this.enableBlock(this.gPrefs.getBoolPref("block.enable"));
this.enableBosskey(this.gPrefs.getBoolPref("bosskey.enable"));
this.minimizeToSysTray(false, this.gPrefs.getBoolPref("minimizeAllToTray"));
this.gWinLoaded = true;
},
onUnLoad: function() {
this.unregister();
},
register: function() {
var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
this._branch = prefService.getBranch("extensions.stm.");
this._branch.QueryInterface(Components.interfaces.nsIPrefBranch2);
this._branch.addObserver("", this, false);
},
unregister: function() {
if(!this._branch) return;
this._branch.removeObserver("", this);
},
observe: function(aSubject, aTopic, aData) {
if(aTopic != "nsPref:changed") return;
switch (aData) {
case "openURLBarInNewTab":
this.openURLBarInNewTab(this.gPrefs.getBoolPref("openURLBarInNewTab"));
break;
case "openBHSInNewTab":
this.enableOpenBHSInNewTab(this.gPrefs.getBoolPref("openBHSInNewTab"));
break;
case "tabBarPosition":
this.chgTabBarPosition(this.gPrefs.getIntPref("tabBarPosition"));
break;
case "newTabBtnPos":
this.chgNewTabBtnPos(this.gPrefs.getIntPref("newTabBtnPos"));
break;
case "tabBarMultiRows":
this.enableMultiTabRows(this.gPrefs.getBoolPref("tabBarMultiRows"));
break;
case "statusbarIcon":
this.showStatusbarIcon(this.gPrefs.getBoolPref("statusbarIcon"));
break;
case "toolMenuItem":
this.showToolMenuItem(this.gPrefs.getBoolPref("toolMenuItem"));
break;
case "doubleClickRemoveTab":
this.enableDoubleClickListener(this.gPrefs.getBoolPref("doubleClickRemoveTab"));
break;
case "showCloseRightTabs":
this.showCloseRightTabsMenu(this.gPrefs.getBoolPref("showCloseRightTabs"));
break;
case "showCloseLeftTabs":
this.showCloseLeftTabsMenu(this.gPrefs.getBoolPref("showCloseLeftTabs"));
break;
case "focusAfterCloseTab":
this.enableFocusAfterCloseTab(this.gPrefs.getIntPref("focusAfterCloseTab"));
break;
case "showHistoryMenu":
this.showHistoryTopMenu(this.gPrefs.getBoolPref("showHistoryMenu"));
break;
case "historyButtonShape":
this.chgHistoryBtnShape(this.gPrefs.getIntPref("historyButtonShape"));
break;
case "urlbarListFontSize":
this.chgURLBarListFontSize(this.gPrefs.getIntPref("urlbarListFontSize"));
break;
case "pagelock.enable":
this.enablePL(this.gPrefs.getBoolPref("pagelock.enable"));
break;
case "pagelock.hotkey":
this.changeHotkey("k.pageLock", this.gPrefs.getCharPref("pagelock.hotkey"));
break;
case "pagelock.enableTabColor":
case "pagelock.enableTabTxtColor":
case "pagelock.tabColor":
case "pagelock.tabTxtColor":
this.changePLTabColor(true);
break;
case "pagelock.showTabMenu":
this.showPLTabMenu(this.gPrefs.getBoolPref("pagelock.showTabMenu"));
break;
case "pagelock.filter":
this.enableFilter(this.gPrefs.getBoolPref("pagelock.filter"));
break;
case "block.enable":
this.enableBlock(this.gPrefs.getBoolPref("block.enable"));
break;
case "block.hotkey":
this.changeHotkey("k.block", this.gPrefs.getCharPref("block.hotkey"));
break;
case "block.stopOnTabSwitch":
this.stopOnTabSwitch(this.gPrefs.getBoolPref("block.stopOnTabSwitch"));
break;
case "bosskey.enable":
this.enableBosskey(this.gPrefs.getBoolPref("bosskey.enable"));
break;
case "bosskey.hidekey":
this.changeHotkey("k.hideFF", this.gPrefs.getCharPref("bosskey.hidekey"));
break;
case "minimizeAllToTray":
this.minimizeToSysTray(true, this.gPrefs.getBoolPref("minimizeAllToTray"));
break;
}
},
openURLBarInNewTab: function(penable) {
var urlbar = document.getElementById("urlbar");
if (penable)
eval("urlbar.handleCommand = " + urlbar.handleCommand.toString().replace(
'if (aTriggeringEvent instanceof MouseEvent) {',
'if (stmM.reloadedSelectedTab(url)) return; if (aTriggeringEvent) {'
));
else
eval("urlbar.handleCommand = " + urlbar.handleCommand.toString().replace(
'if (aTriggeringEvent) {',
'if (aTriggeringEvent instanceof MouseEvent) {'
).replace(
'stmM.reloadedSelectedTab(url)',
'false'
));
},
reloadedSelectedTab: function(url) {
document.getElementById("urlbar").handleRevert();
gBrowser.selectedBrowser.focus();
if (url == gBrowser.selectedBrowser.contentDocument.URL) {
gBrowser.selectedBrowser.reload();
return true;
} else
return false;
},
/* enable open bookmark/history/search in new tab */
enableOpenBHSInNewTab: function(penable) {
if (penable) {
eval("openUILinkIn = " + openUILinkIn.toString().replace(
'switch (where)',
'switch (stmC.onTabSwitch(url, where))'
));
var sbar = document.getElementById("searchbar");
eval("sbar.handleSearchCommand = " + sbar.handleSearchCommand.toString().replace(
'where = "tab";',
'where = stmC.onTabSwitch("", "current");'
));
eval("PlacesUIUtils._openTabset = " + PlacesUIUtils._openTabset.toString().replace(
'(urls, loadInBackground, replaceCurrentTab);',
'(urls, loadInBackground, false);'
));
} else {
eval("openUILinkIn = " + openUILinkIn.toString().replace(
'switch (stmC.onTabSwitch(url, where))',
'switch (where)'
));
var sbar = document.getElementById("searchbar");
eval("sbar.handleSearchCommand = " + sbar.handleSearchCommand.toString().replace(
'where = stmC.onTabSwitch("", "current");',
'where = "tab";'
));
eval("PlacesUIUtils._openTabset = " + PlacesUIUtils._openTabset.toString().replace(
'(urls, loadInBackground, false);',
'(urls, loadInBackground, replaceCurrentTab);'
));
}
},
doEvalAtStart: function() {
//execute removeBlankTab() in openUILinkIn()
eval("openUILinkIn = " + openUILinkIn.toString().replace(
'switch (',
'stmM.removeBlankTab(gBrowser.mCurrentTab); switch ('
));
eval("nsContextMenu.prototype.initMenu = " + nsContextMenu.prototype.initMenu.toString().replace(
'this.initItems();',
'this.initItems(); stmM.initMenuOfLoadSelect();'
));
var el = document.getAnonymousElementByAttribute(gBrowser, 'anonid', 'tabContextMenu');
el.setAttribute("onpopupshowing", "stmM.initTabContextMenu(); this.parentNode.parentNode.parentNode.updatePopupMenu(this);");
},
/* enable new tab position */
enableNewTabPosition: function() {
eval("gBrowser.addTab = " + gBrowser.addTab.toString().replace(
'return t;',
'return stmM.whereAddTab(t, aOwner, blank);'
));
},
/* Where to add New Tab */
whereAddTab: function(t, aOwner, blank) {
var func = this.whereAddTab.caller.caller.name;
if (!blank && func && ["_endRemoveTab","sss_restoreWindow","sss_undoCloseTab"].indexOf(func) == -1)
this.removeBlankTab(t);
if (this.gPrefs.getBoolPref("newTabPosBackTabOnly"))
if (aOwner) return t; // Do not handle bookmarks or history or search that open on foreground
var wtabs = gBrowser.tabContainer;
var s = gBrowser.selectedTab;
switch(this.gPrefs.getIntPref("newTabPosition")) {
case 1: //right near current tab
if (wtabs.itemCount >= 2)
gBrowser.moveTabTo(t, wtabs.selectedIndex + 1);
case 0:
if (!s.hasAttribute("stmTabMark"))
s.setAttribute("stmTabMark", Math.random());
t.setAttribute("stmRightMark", s.getAttribute("stmTabMark"));
break;
case 2: //right far from current tab
gBrowser.moveTabTo(t, wtabs.itemCount - 1);
if (s.hasAttribute("stmTabMark")) {
var lindex;
for (var i = wtabs.selectedIndex + 1; i < wtabs.itemCount; i++) {
if (gBrowser.mTabs[i].getAttribute("stmRightMark") == s.getAttribute("stmTabMark")) lindex = i;
else break;
}
if (lindex)
gBrowser.moveTabTo(t, lindex + 1);
else
gBrowser.moveTabTo(t, wtabs.selectedIndex + 1);
} else {
s.setAttribute("stmTabMark", Math.random());
if (wtabs.itemCount >= 2)
gBrowser.moveTabTo(t, wtabs.selectedIndex + 1);
}
t.setAttribute("stmRightMark", s.getAttribute("stmTabMark"));
break;
case 3: //rightest
if (wtabs.itemCount >= 2)
gBrowser.moveTabTo(t, wtabs.itemCount);
if (!s.hasAttribute("stmTabMark"))
s.setAttribute("stmTabMark", Math.random());
t.setAttribute("stmRightMark", s.getAttribute("stmTabMark"));
break;
}
return t;
},
removeBlankTab: function(tab) {
if (!this.gPrefs.getBoolPref("openInBlankTab")) return;
for(var i = gBrowser.browsers.length - 1; i >= 0; i--) {
var t = gBrowser.mTabs[i];
if (t == tab) continue;
if (gBrowser.getBrowserAtIndex(i).currentURI.spec == 'about:blank' && !t.getAttribute("busy"))
gBrowser.removeTab(t);
}
},
/* change tab bar position */
chgTabBarPosition: function(pint) {
var position;
switch (pint) {
case 0:
position = "";
break;
case 1:
position = "-moz-box-direction: reverse;";
break;
}
try {
for(var i = 0; i < document.styleSheets.length; i++) {
var ss = document.styleSheets[i];
if(ss.href == "chrome://supertabmode/skin/stm.css") {
ss.deleteRule(3);
ss.insertRule("#content > tabbox {" + position + "}", 3);
break;
}
}
}
catch(e){ alert("chgTabBarPosition error"); }
},
chgNewTabBtnPos: function(pint) {
var i_nb = document.getAnonymousElementByAttribute(gBrowser.mTabContainer, 'anonid', 'arrowscrollbox')
.getElementsByAttribute('class', 'tabs-newtab-button')[0]
var r_nb = document.getAnonymousElementByAttribute(gBrowser.mTabContainer, 'anonid', 'newtab-button');
var button = gBrowser.mTabContainer.previousSibling;
switch (pint) {
case 0: //default
if (button.getAttribute("class") == "stm-leftnewbutton") gBrowser.mStrip.removeChild(button);
i_nb.setAttribute('hidden', 'false');
r_nb.setAttribute('hidden', 'false');
var node = gBrowser.mStrip.lastChild;
gBrowser.mStrip.appendChild(node, node); //refresh
break;
case 1: //left
if (button.getAttribute("class") != "stm-leftnewbutton") {
var l_nb = i_nb.cloneNode(true);
l_nb.setAttribute('class', 'stm-leftnewbutton');
gBrowser.mStrip.insertBefore(l_nb, gBrowser.mTabContainer);
}
i_nb.setAttribute('hidden', 'true');
r_nb.setAttribute('hidden', 'true');
break;
case 2: //hide
if (button.getAttribute("class") == "stm-leftnewbutton") gBrowser.mStrip.removeChild(button);
i_nb.setAttribute('hidden', 'true');
r_nb.setAttribute('hidden', 'false');
break;
}
},
enableMultiTabRows: function(penable) {
if (penable) {
eval("gBrowser.moveTabTo = " + gBrowser.moveTabTo.toString().replace(
'this.mTabContainer.mTabstrip.scrollBoxObject.ensureElementIsVisible(this.mCurrentTab);',
'stmM.doNothing();'
));
this.prepareMultiTabRows(true);
window.addEventListener("resize", this.toggleMultiTabRows, false);
this.toggleMultiTabRows("start");
} else {
eval("gBrowser.moveTabTo = " + gBrowser.moveTabTo.toString().replace(
'stmM.doNothing();',
'this.mTabContainer.mTabstrip.scrollBoxObject.ensureElementIsVisible(this.mCurrentTab);'
));
this.prepareMultiTabRows(false);
window.removeEventListener("resize", this.toggleMultiTabRows, false);
this.toggleMultiTabRows("stop");
}
},
prepareMultiTabRows: function(penable) {
var css = new Array();
css[8] = '.tabbrowser-arrowscrollbox > .scrollbutton-up, .tabbrowser-arrowscrollbox > .scrollbutton-down {'
+ (penable?'display: none;':"") + '}';
css[9] = '.tabbrowser-arrowscrollbox > .tabs-newtab-button {' + (penable?'visibility: visible;':"") + '}';
css[10]= '.tabs-container > .tabs-newtab-button {' + (penable?'display: none;':"") + '}';
for(var i = 0; i < document.styleSheets.length; i++) {
var ss = document.styleSheets[i];
if(ss.href == "chrome://supertabmode/skin/stm.css") {
for (var j = 8; j <= 10; j++) {
ss.deleteRule(j);
ss.insertRule(css[j], j);
}
break;
}
}
},
/* param: "start", "stop", event */
toggleMultiTabRows: function(e){
var newBtnWidth = 0;
switch (stmM.gPrefs.getIntPref("newTabBtnPos")) {
case 0:
newBtnWidth = 28; break; // 28 comes from DOM Inspector
case 1:
newBtnWidth = 0; break;
case 2:
newBtnWidth = 0; break;
}
var barwidth = gBrowser.mTabContainer.mTabstrip.scrollBoxObject.width - newBtnWidth;
var tabwidth = gBrowser.mTabContainer.mTabMinWidth;
tabwidth = tabwidth < 32 ? 32:tabwidth; //32 comes from calculated min width
var self = stmM.toggleMultiTabRows;
if (e == "start") {
if (tabwidth*(gBrowser.mTabs.length) <= barwidth || gBrowser.mTabs.length == 1) {
gBrowser.tabContainer.addEventListener('TabOpen', self, false);
return;
} else gBrowser.tabContainer.addEventListener('TabClose', self, false);
} else if (e == "stop") {
gBrowser.tabContainer.removeEventListener('TabOpen', self, false);
gBrowser.tabContainer.removeEventListener('TabClose', self, false);
} else if (e && e.type == "resize") {
if (stmM.gOldScrollBoxWidth != -1) {
if (Math.abs(stmM.gOldScrollBoxWidth - barwidth) < 10) return; //10 is randomly defined
if (stmM.gOldScrollBoxWidth > barwidth) { //smaller
if (tabwidth*(gBrowser.mTabs.length) <= barwidth) {stmM.gOldScrollBoxWidth = barwidth; return;}
stmM.doTabRowsListener('TabOpen');
e = "start";
} else if (stmM.gOldScrollBoxWidth < barwidth) { //bigger
if (tabwidth*(gBrowser.mTabs.length-1) > barwidth) {stmM.gOldScrollBoxWidth = barwidth; return;}
stmM.doTabRowsListener('TabClose');
e = "stop";
}
}
stmM.gOldScrollBoxWidth = barwidth;
} else if (e && e.type == 'TabOpen') {
if (tabwidth*(gBrowser.mTabs.length) <= barwidth || gBrowser.mTabs.length == 1) return;
stmM.doTabRowsListener('TabOpen');
} else if (e && e.type == 'TabClose') {
if (tabwidth*(gBrowser.mTabs.length-1) > barwidth) return;
stmM.doTabRowsListener('TabClose');
}
var css = new Array();
css[4] = '.tabbrowser-arrowscrollbox > scrollbox > box {'
+ ((e == "start" || e.type == "TabOpen")?"display: block;":"") + '}';
css[5] = '.tabbrowser-arrowscrollbox > scrollbox {'
+ ((e == "start" || e.type == "TabOpen")?"overflow: visible;":"") + '}';
css[6] = '.tabbrowser-tab[selected="true"] {'
+ ((e == "start" || e.type == "TabOpen")?"padding: 2px 1px 2px 1px;border: 1px solid;border-bottom: none;":"") + '}';
css[7] = '.tabbrowser-tab {'
+ ((e == "start" || e.type == "TabOpen")?"padding: 2px 1px 1px 1px;border: 1px solid;border-bottom: none;":"") + '}';
for(var i = 0; i < document.styleSheets.length; i++) {
var ss = document.styleSheets[i];
if(ss.href == "chrome://supertabmode/skin/stm.css") {
for (var j = 4; j <= 7; j++) {
ss.deleteRule(j);
ss.insertRule(css[j], j);
}
break;
}
}
},
doTabRowsListener: function(en) {
var c = gBrowser.tabContainer;
var t = stmM.toggleMultiTabRows;
c.removeEventListener(en=="TabOpen"?"TabOpen":"TabClose", t, false);
c.addEventListener(en=="TabOpen"?"TabClose":"TabOpen", t, false);
},
/* enable double click listener */
enableDoubleClickListener: function(penable) {
var r = this.removeDoubleClickListener;
if (penable) {
gBrowser.mTabContainer.addEventListener('dblclick', this.onMouseDoubleClick, false);
window.addEventListener("unload", r, false);
} else {
this.removeDoubleClickListener();
window.removeEventListener("unload", r, false);
}
},
/* remove double click listener */
removeDoubleClickListener: function(e) {
gBrowser.mTabContainer.removeEventListener('dblclick', this.onMouseDoubleClick, false);
},
/* double click to close a tab */
onMouseDoubleClick: function(e) {
if (e.target.localName == 'tab' && e.button == 0 && !e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey && !e.getPreventDefault())
gBrowser.removeTab(e.target);
},
enableFocusAfterCloseTab: function(position) {
if (position == 0) {
eval("gBrowser._endRemoveTab = " + gBrowser._endRemoveTab.toString().replace(
'stmM.doNothing();',
'this._blurTab(aTab);'
).replace(
'stmM.afterRemoveTab(aTab);',
''
));
eval("gBrowser.removeAllTabsBut = " + gBrowser.removeAllTabsBut.toString().replace(
'stmM.closeAllTabsBut(aTab);',
'this.selectedTab = aTab;'
));
eval("gBrowser.removeAllTabsBut = " + gBrowser.removeAllTabsBut.toString().replace(
'return;',
''
));
} else {
eval("gBrowser._endRemoveTab = " + gBrowser._endRemoveTab.toString().replace(
'this._blurTab(aTab);',
'stmM.doNothing();'
).replace(
'this.selectedTab._selected = true;',
'stmM.afterRemoveTab(aTab);this.selectedTab._selected = true;'
));
eval("gBrowser.removeAllTabsBut = " + gBrowser.removeAllTabsBut.toString().replace(
'this.selectedTab = aTab;',
'stmM.closeAllTabsBut(aTab); return;'
)); //make closeAllTabsBut() look smoothly.
}
var c = gBrowser.tabContainer;
var l = this.setLastSelectedTab;
if (position == 7) c.addEventListener('select', l, false);
else c.removeEventListener('select', l, false);
},
doNothing: function() {
return;
},
setLastSelectedTab: function() {
var newtab = gBrowser.selectedTab;
if (stmM.arrayTop == 0) {
stmM.openedTabs[stmM.arrayTop++] = gBrowser.mTabs[0];
}
var finded = -1;
for (var i=0; i<stmM.arrayTop; i++) {
if (stmM.openedTabs[i] == newtab) {
finded = i;
break;
}
}
if (finded > -1) {
for (var i=finded; i<stmM.arrayTop-1; i++) {
stmM.openedTabs[i] = stmM.openedTabs[i+1];
}
stmM.openedTabs[stmM.arrayTop-1] = newtab;
} else
stmM.openedTabs[stmM.arrayTop++] = newtab;
},
afterRemoveTab: function(aTab) {
if (gBrowser.mCurrentTab != aTab) return; //remove tab which is not selected
var wStmRightMark = aTab.getAttribute("stmRightMark");
var wStmTabMark = aTab.getAttribute("stmTabMark");
var wIndex = aTab._tPos;
switch (this.gPrefs.getIntPref("focusAfterCloseTab")) {
case 1: //left
gBrowser.selectedTab = gBrowser.mTabs[wIndex-1>=0?wIndex-1:0];
return;
break;
case 2: //father, no father ->child first
if (!wStmRightMark) break;
var findex = this.getFatherTabIndex(wStmRightMark);
if (findex >= 0) {gBrowser.selectedTab = gBrowser.mTabs[findex]; return;}
for(var i = 0; i < gBrowser.mTabs.length; i++) {
var ctab = gBrowser.mTabs[i];
if (ctab.getAttribute("stmRightMark") == wStmRightMark)
{gBrowser.selectedTab = ctab; return;}
}
break;
case 3: //father right first, if no, father
if (!wStmRightMark) break;
var findex = this.getFatherTabIndex(wStmRightMark);
for(var i = (findex==-1?0:findex+1); i < gBrowser.mTabs.length; i++) {
var ctab = gBrowser.mTabs[i];
if (ctab.getAttribute("stmRightMark") == wStmRightMark)
{gBrowser.selectedTab = ctab; return;}
}
if (findex >= 0) {gBrowser.selectedTab = gBrowser.mTabs[findex]; return;}
break;
case 4: //father right farest, if no, father
if (!wStmRightMark) break;
var findex = this.getFatherTabIndex(wStmRightMark);
var lchildtab;
for(var i = (findex==-1?0:findex+1); i < gBrowser.mTabs.length; i++) {
var ctab = gBrowser.mTabs[i];
if (ctab.getAttribute("stmRightMark") == wStmRightMark)
lchildtab = ctab;
}
if (lchildtab) {gBrowser.selectedTab = lchildtab; return;}
if (findex >= 0) {gBrowser.selectedTab = gBrowser.mTabs[findex]; return;}
break;
case 5: //first
gBrowser.selectedTab = gBrowser.mTabs[0]; return;
break;
case 6: //last
gBrowser.selectedTab = gBrowser.mTabs[gBrowser.mTabs.length - 1]; return;
break;
case 7: //last selected tab
this.openedTabs[this.arrayTop-1] = null;
if (--this.arrayTop < 1) break;
gBrowser.selectedTab = this.openedTabs[this.arrayTop-1];
return;
case 8: //author's like
var cindex = this.findChildNotFather(wIndex, wStmRightMark);
if (cindex != -1) {gBrowser.selectedTab = gBrowser.mTabs[cindex]; return;}
if (!wStmTabMark) {
var findex = this.getFatherTabIndex(wStmRightMark);
if (findex != -1) {gBrowser.selectedTab = gBrowser.mTabs[findex]; return; }
}
cindex = this.findChildNotFather(wIndex);
if (cindex != -1) {gBrowser.selectedTab = gBrowser.mTabs[cindex]; return;}
break;
}
gBrowser.selectedTab = gBrowser.mTabs[wIndex==gBrowser.mTabs.length?wIndex-1:wIndex]; //default
},
getFatherTabIndex: function(pstmmark) {
for(var i = 0; i < gBrowser.mTabs.length; i++) {
var ctab = gBrowser.mTabs[i];
if (ctab.getAttribute("stmTabMark") == pstmmark) return i;
}
return -1;
},
//no 2nd param: find any child; with 2nd param: find child with same father
findChildNotFather: function(pcindex, pstmmark) {
for(var i = pcindex; i < gBrowser.mTabs.length; i++) {
var ctab = gBrowser.mTabs[i];
if (!ctab.hasAttribute("stmTabMark")) {
if (pstmmark) {if (pstmmark == ctab.getAttribute("stmRightMark")) return i;}
else if (ctab.hasAttribute("stmRightMark")) return i;
}
}
for(var i = pcindex - 1; i >= 0; i--) {
var ctab = gBrowser.mTabs[i];
if (!ctab.hasAttribute("stmTabMark")) {
if (pstmmark) {if (pstmmark == ctab.getAttribute("stmRightMark")) return i;}
else if (ctab.hasAttribute("stmRightMark")) return i;
}
}
return -1;
},
showHistoryTopMenu: function(pshow) {
document.getElementById("tabreopen-menu").setAttribute("hidden", !pshow);
},
chgHistoryBtnShape: function(pshape) {
var e = document.getElementById("b.historybutton");
if (pshape == 0) {
e.setAttribute("oncommand", "document.getElementById('historybutton-popup').openPopup(this, 'after_start');");
e.setAttribute("type", "");
} else {
e.setAttribute("oncommand", "undoCloseTab();");
e.setAttribute("type", "menu-button");
}
},
showHistoryMenuItems: function(menupopup) {
var undoPopup = menupopup;
// remove existing menu items
while (undoPopup.hasChildNodes())
undoPopup.removeChild(undoPopup.firstChild);
// no restorable tabs, so return
if (HistoryMenu._ss.getClosedTabCount(window) == 0) {
var m = document.createElement("menuitem");
m.setAttribute("label", document.getElementById("stm.stringmanager").getString("history.empty"));
undoPopup.appendChild(m);
return;
}
// populate menu
var undoItems = eval("(" + HistoryMenu._ss.getClosedTabData(window) + ")");
for (var i = 0; i < undoItems.length; i++) {
var m = document.createElement("menuitem");
m.setAttribute("label", undoItems[i].title);
if (undoItems[i].image) {
let iconURL = undoItems[i].image;
// don't initiate a connection just to fetch a favicon (see bug 467828)
if (/^https?:/.test(iconURL))
iconURL = "moz-anno:favicon:" + iconURL;
m.setAttribute("image", iconURL);
}
m.setAttribute("class", "menuitem-iconic bookmark-item");
m.setAttribute("value", i);
m.setAttribute("oncommand", "undoCloseTab(" + i + ");event.stopPropagation();");
//firefox version
if (this.gFFVersion == "3.5")
m.addEventListener("click", undoCloseMiddleClick, false);
else
m.addEventListener("click", HistoryMenu._undoCloseMiddleClick, false);
if (i == 0)
m.setAttribute("key", "key_undoCloseTab");
undoPopup.appendChild(m);
}
// "Open All in Tabs"
var strings = gNavigatorBundle;
undoPopup.appendChild(document.createElement("menuseparator"));
m = undoPopup.appendChild(document.createElement("menuitem"));
//firefox version
if (this.gFFVersion == "3.5") {
m.setAttribute("label", strings.getString("menuOpenAllInTabs.label"));
m.setAttribute("accesskey", strings.getString("menuOpenAllInTabs.accesskey"));
} else {
m.id = "menu_restoreAllTabs";
m.setAttribute("label", strings.getString("menuRestoreAllTabs.label"));
m.setAttribute("accesskey", strings.getString("menuRestoreAllTabs.accesskey"));
}
m.addEventListener("command", function() {
for (var i = 0; i < undoItems.length; i++)
undoCloseTab();
}, false);
},
/* change urlbar list font size */
chgURLBarListFontSize: function(pint) {
var fontstyle, fontsize;
switch (pint) {
case 0: break;
case 1: fontsize = "xx-small"; break;
case 2: fontsize = "x-small"; break;
case 3: fontsize = "small"; break;
case 4: fontsize = "medium"; break;
case 5: fontsize = "large"; break;
case 6: fontsize = "x-large"; break;
case 7: fontsize = "x-large"; break;
}
if (pint == 0)
fontstyle = "";
else
fontstyle = "font-size: " + fontsize + " !important;";
try {
for(var i = 0; i < document.styleSheets.length; i++) {
var ss = document.styleSheets[i];
if(ss.href == "chrome://supertabmode/skin/stm.css") {
ss.deleteRule(2);
ss.insertRule(".ac-comment {" + fontstyle + "}", 2);
break;
}
}
}
catch(e){ alert("chgURLBarListFontSize error"); }
},
/* load selected text in a new tab */
loadSelectInTab: function() {
var w = document.commandDispatcher.focusedWindow;
var s = stmC.trim(w.getSelection().toString());
if (s.substr(0, 4).toUpperCase() != "HTTP")
s = "http://" + s;
openNewTabWith(s, gBrowser.contentDocument);
},
/* init menu of loading selected text in a new tab */
initMenuOfLoadSelect: function() {
if (!this.gPrefs.getBoolPref("showLoadSelectMenu")) {
document.getElementById("stm.context-loadselect").hidden = true;
return;
}
var s = getBrowserSelection(15);
if (s.indexOf(".") >= 0) {
if (getBrowserSelection().length > s.length)
s += "...";
var sb = document.getElementById("stm.stringmanager");
s = sb.getString("loadselectmenu.label") + ' "' + s + '"';
document.getElementById("stm.context-loadselect").label = s;
document.getElementById("stm.context-loadselect").hidden = false;
} else {
document.getElementById("stm.context-loadselect").hidden = true;
}
},
/* show/hide tool menu item */
showToolMenuItem: function(pshow) {
document.getElementById("stm.menuitem").setAttribute("hidden", !pshow);
},
/* open preference window from tool menu*/
openPrefDialog: function() {
const prefURL = "chrome://supertabmode/content/preference.xul";
var features = "chrome,titlebar,toolbar,centerscreen,modal";
window.openDialog(prefURL, "", features);
},
/* enable pagelock */
enablePL: function(penable) {
if (penable) {
this.gFFContentAreaClick = window.contentAreaClick;
window.contentAreaClick = this.patchedContentAreaClick;
this.enablePLHotKey(true);
this.enablePLMouseKey(true);
this.changePLTabColor(true);
this.showPLTabMenu(this.gPrefs.getBoolPref("pagelock.showTabMenu"));
this.showPLStatusbarMenu(this.gPrefs.getBoolPref("pagelock.showStatusbarMenu"));
if (this.gWinLoaded) this.toggleToolbarButton(TME_TOOLBARBUTTON, true);
this.enableFilter(this.gPrefs.getBoolPref("pagelock.filter"));
} else {
if (this.gFFContentAreaClick) window.contentAreaClick = this.gFFContentAreaClick;
this.enablePLHotKey(false);
this.enablePLMouseKey(false);
this.changePLTabColor(false);
this.showPLTabMenu(false);
this.showPLStatusbarMenu(false);
if (this.gWinLoaded) this.toggleToolbarButton(TME_TOOLBARBUTTON, false);
this.enableFilter(false);
}
},
/* patched firefox ContentAreaClick function (pagelock) */
patchedContentAreaClick: function(e, fieldNormalClicks) {
if (gBrowser.selectedTab.getAttribute("isPageLocked") == "true"
&& (e.target.localName.toUpperCase() == "A" || e.target.parentNode.localName.toUpperCase() == "A"))
if(e.button == 0 && !e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey && !e.getPreventDefault()) {
var newEvent = document.createEvent("MouseEvents");
newEvent.initMouseEvent("click", e.bubbles, e.cancelable, e.view, e.detail, e.screenX, e.screenY, e.clientX, e.clientY, true, e.altKey, e.shiftKey, e.metaKey, e.button, e.relatedTarget);
e.preventDefault();
e.stopPropagation();
e.target.dispatchEvent(newEvent);
return;
}
stmM.gFFContentAreaClick(e, fieldNormalClicks);
return;
},
/* enable pagelock toggle keypress */
enablePLHotKey: function(penable) {
if (penable)
document.getElementById("k.pageLock").setAttribute("disabled", false);
else
document.getElementById("k.pageLock").setAttribute("disabled", true);
},
/* enable pagelock toggle mouse listener */
enablePLMouseKey: function(penable) {
var r = this.removeMouseKeyListener;
if (penable) {
gBrowser.mTabContainer.addEventListener('click', this.onPLMouseKey, false);
window.addEventListener("unload", r, false);
} else {
this.removeMouseKeyListener();
window.removeEventListener("unload", r, false);
}
},
/* remove pagelock mouse key listener */
removeMouseKeyListener: function(e) {
gBrowser.mTabContainer.removeEventListener('click', this.onPLMouseKey, false);
},
/* mouse key to toggle pagelock */
onPLMouseKey: function(e) {
switch(stmM.gPrefs.getIntPref("pagelock.mousekey"))
{
case 0: /* ctrl key */
if(e.altKey || !e.ctrlKey || e.shiftKey || e.metaKey || e.button != 0 || e.getPreventDefault())
return;
break;
case 1: /* shift key */
if(e.altKey || e.ctrlKey || !e.shiftKey || e.metaKey || e.button != 0 || e.getPreventDefault())
return;
break;
default: // Error
alert("unknown error: swich to default!");
return;
}
stmM.togglePL();
},
/* toggle pagelock */
togglePL: function() {
var url = gBrowser.selectedBrowser.contentDocument.URL;
if (url == "about:blank") return;
var t = gBrowser.selectedTab;
if (t.getAttribute("isPageLocked") == "true") {
t.removeAttribute("isPageLocked");
}
else {
t.setAttribute("isPageLocked", "true");
}
},
changeHotkey: function(pename, photkey) {
var list = photkey.split("|:|")[1].split("[+]");
var mykey = document.getElementById(pename);
mykey.removeAttribute("keycode");
mykey.removeAttribute("key");
mykey.removeAttribute("modifiers");
if (list[0]) mykey.setAttribute("keycode", list[0]);
if (list[1]) mykey.setAttribute("key", list[1]);
if (list[2]) mykey.setAttribute("modifiers", list[2]);
//try to invalidate cache
var keyset = mykey.parentNode;
keyset.parentNode.insertBefore(keyset, keyset.nextSibling);
},
/* change pagelock tab color */
changePLTabColor: function(penable) {
var bkcolorrule, txtcolorrule;
if (penable) {
var enable = this.gPrefs.getBoolPref("pagelock.enableTabColor");
var color = this.gPrefs.getCharPref("pagelock.tabColor");
bkcolorrule = enable==true?("background-color: " + color + " !important;") : "";
enable = this.gPrefs.getBoolPref("pagelock.enableTabTxtColor");
color = this.gPrefs.getCharPref("pagelock.tabTxtColor");
txtcolorrule = enable==true?("color: " + color + " !important;") : "";
} else {
colorrule = "";
textcolorrule = "";
}
try {
for(var i = 0; i < document.styleSheets.length; i++) {
var ss = document.styleSheets[i];
if(ss.href == "chrome://supertabmode/skin/stm.css") {
ss.deleteRule(1);
ss.insertRule("#browser tab.tabbrowser-tab[isPageLocked=true] {" + bkcolorrule + txtcolorrule + "}", 1);
break;
}
}
}
catch(e){ alert("coloratePageLockTab error"); }
},
/* add Tab context menu */
addTabMenu: function() {
var m = gBrowser.mStrip.firstChild.nextSibling;
var f = m.firstChild;
if (f) {
for (var i=0; i<=2; i++)
m.insertBefore(document.getElementById("stm.tabBlockScope" + i), f);
m.insertBefore(document.getElementById("stm.tmSepa2"), f);
m.insertBefore(document.getElementById("stm.tabBlockStopOnTabSwitch"), f);
m.insertBefore(document.getElementById("stm.tmSepa1"), f);
for (var i=0; i<=2; i++)
m.insertBefore(document.getElementById("stm.tabpagelock" + i), f);
m.insertBefore(document.getElementById("stm.tmSepa0"), f);
}
var cm = document.getElementById("context_closeOtherTabs");
if (cm) {
m.insertBefore(document.getElementById("stm.tCloseRTabs"), cm);
m.insertBefore(document.getElementById("stm.tCloseLTabs"), cm);
}
},
initTabContextMenu: function() {
var b = this.gPrefs.getBoolPref("block.enable") && this.gPrefs.getBoolPref("block.showTabMenu");
this.showBlockTabMenu(b);
if (!b) return;
document.getElementById("stm.tabBlockStopOnTabSwitch").setAttribute("checked", this.gPrefs.getBoolPref("block.stopOnTabSwitch"));
for (var i=0; i<=2; i++) {
document.getElementById("stm.tabBlockScope" + i).setAttribute("checked", (this.gPrefs.getIntPref("block.blockScope") == i && this.gBlockingOn));
}
},
/* show/hide tab context pagelock menu */
showPLTabMenu: function(penable) {
for (var i=0; i<=2; i++)
document.getElementById("stm.tabpagelock" + i).setAttribute("hidden", !penable);
document.getElementById("stm.tmSepa0").setAttribute("hidden", !penable);
},
/* show/hide tab context Close right tabs menu */
showCloseRightTabsMenu: function(penable) {
document.getElementById("stm.tCloseRTabs").setAttribute("hidden", !penable);
},
/* show/hide tab context Close left tabs menu */
showCloseLeftTabsMenu: function(penable) {
document.getElementById("stm.tCloseLTabs").setAttribute("hidden", !penable);
},
/* close right tabs */
closeRightTabs: function() {
this.enableFocusAfterCloseTab(0); //make closing look smoothly
var aTab;
if (this.closeByKey)
aTab = gBrowser.selectedTab;
else
aTab = gBrowser.mContextTab;
gBrowser.selectedTab = aTab;
for (let i = gBrowser.mTabs.length - 1; i > aTab._tPos; --i) {
gBrowser.removeTab(gBrowser.mTabs[i]);
}
gBrowser.selectedTab = aTab;
this.enableFocusAfterCloseTab(this.gPrefs.getIntPref("focusAfterCloseTab"));
this.closeByKey = false;
},
/* close left tabs */
closeLeftTabs: function() {
this.enableFocusAfterCloseTab(0); //make closing look smoothly
var aTab;
if (this.closeByKey)
aTab = gBrowser.selectedTab;
else
aTab = gBrowser.mContextTab;
gBrowser.selectedTab = aTab;
for(var i = aTab._tPos - 1; i >= 0; i--) {
gBrowser.removeTab(gBrowser.mTabs[i]);
}
gBrowser.selectedTab = aTab;
this.enableFocusAfterCloseTab(this.gPrefs.getIntPref("focusAfterCloseTab"));
this.closeByKey = false;
},
closeAllTabsBut: function(aTab) {
if (this.gPrefs.getIntPref("focusAfterCloseTab") != 0 )
eval("gBrowser._endRemoveTab = " + gBrowser._endRemoveTab.toString().replace(
'stmM.doNothing();',
'this._blurTab(aTab);'
).replace(
'stmM.afterRemoveTab(aTab);',
''
));
gBrowser.selectedTab = aTab;
for (let i = gBrowser.mTabs.length - 1; i >= 0; --i) {
if (gBrowser.mTabs[i] != aTab)
gBrowser.removeTab(gBrowser.mTabs[i]);
}
if (this.gPrefs.getIntPref("focusAfterCloseTab") != 0 )
eval("gBrowser._endRemoveTab = " + gBrowser._endRemoveTab.toString().replace(
'this._blurTab(aTab);',
'stmM.doNothing();'
).replace(
'this.selectedTab._selected = true;',
'stmM.afterRemoveTab(aTab);this.selectedTab._selected = true;'
));
},
showPLStatusbarMenu: function(penable) {
document.getElementById("stm.managelist").setAttribute("hidden", !penable);
document.getElementById("stm.keeppagelocked").setAttribute("hidden", !penable);
document.getElementById("stm.smSepa0").setAttribute("hidden", !penable);
},
/* toggle toolbar button. true:show, false:hide, no parameter:toggle */
toggleToolbarButton: function(bname, penable) {
var navbar = document.getElementById("nav-bar");
var curSet = navbar.currentSet;
var set;
if (curSet.indexOf(bname) == -1) {
if (penable == false) return;
// Place the button before the urlbar
if (curSet.indexOf("urlbar-container") != -1)
set = curSet.replace(/urlbar-container/, bname + ",urlbar-container");
else // at the end
set = curSet + "," + bname;
} else {
if (penable == true) return;
if (curSet.indexOf(bname)==0) //toolbutton is at the most left
set = curSet.replace(bname + "," , "");
else
set = curSet.replace("," + bname, "");
}
navbar.setAttribute("currentset", set);
navbar.currentSet = set;
document.persist("nav-bar", "currentset");
// If you don't do the following call, funny things happen
//try { BrowserToolboxCustomizeDone(true); } catch (e) { }
},
/* toolbar button click */
onToolbarButtonClick: function(e) {
if (!this.gPrefs.getBoolPref("pagelock.enable")){
var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
var sb = document.getElementById("stm.stringmanager");
if (prompts.confirm(null, sb.getString("pagelockdisabled.title"), sb.getString("pagelockdisabled")))
this.gPrefs.setBoolPref("pagelock.enable", true);
else
return;
}
this.togglePL();
},
/* pagelock tab Menu click */
onTabMenuPageLockClick: function(e) {
gBrowser.selectedTab = gBrowser.mContextTab;
this.togglePL();
},
/* toggle statusbar icon */
showStatusbarIcon: function(pshow) {
document.getElementById("stm.statuspanel").setAttribute("hidden", !pshow);
},
/* statusbar icon click */
onStatusbarIconClick: function(e) {
switch(e.button) {
case 0:
if (!this.gPrefs.getBoolPref("pagelock.enable")){
var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
var sb = document.getElementById("stm.stringmanager");
if (prompts.confirm(null, sb.getString("pagelockdisabled.title"), sb.getString("pagelockdisabled")))
this.gPrefs.setBoolPref("pagelock.enable", true);
else
return;
}
this.togglePL();
break;
case 1:
if (!this.gPrefs.getBoolPref("block.enable")){
var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
var sb = document.getElementById("stm.stringmanager");
if (prompts.confirm(null, sb.getString("blockdisabled.title"), sb.getString("blockdisabled")))
this.gPrefs.setBoolPref("block.enable", true);
else
return;
}
this.toggleBlock();
break;
case 2:
var b = this.gPrefs.getBoolPref("block.enable") && this.gPrefs.getBoolPref("block.showStatusbarMenu");
this.showBlockStatusbarMenu(b);
b = this.gPrefs.getBoolPref("pagelock.enable") && this.gPrefs.getBoolPref("pagelock.showStatusbarMenu");
this.showPLStatusbarMenu(b);
document.getElementById("stm.popup").openPopup(e.target, "before_start");
break;
}
},
/* click exit at statusbar icon right-click menu*/
onExitStatusbarIcon: function() {
this.gPrefs.setBoolPref("statusbarIcon", false);
},
onTabMenuAddIntoListClick: function() {
gBrowser.selectedTab = gBrowser.mContextTab;
this.addIntoList();
},
/* add into auto-pagelock url list*/
addIntoList: function(e) {
gBrowser.selectedTab = gBrowser.mContextTab;
var rule = gBrowser.currentURI.spec;
var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
var sb = document.getElementById("stm.stringmanager");
if (!prompts.confirm(null, null, sb.getString("urlInsertPrompt") + "\n\n" + gBrowser.currentURI.spec + "\n ")) return;
if (rule != "" && rule != "about:blank") {
if (rule.indexOf("://") < 0) {
rule = (/^[A-Za-z]:/.test(rule) ? "file:///"+rule.replace(/\\/g,"/") : "http://"+rule+"/");
if (/^file:\/\/.*/.test(rule)) rule = encodeURI(rule);
}
rule = rule.replace(/\s/g, "%20");
var s = this.gPrefs.getComplexValue("pagelock.filterlist", Components.interfaces.nsISupportsString).data;
var list = (s ? s.split(" ") : "");
for (var i = 0; i < list.length; i++) {
var item = list[i].split("\b");
if (item[0] == rule){
prompts.alert(null, null, sb.getString("urlInsertError"));
return;
}
}
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
str.data = s + " " + rule;
this.gPrefs.setComplexValue("pagelock.filterlist", Components.interfaces.nsISupportsString, str);
gBrowser.selectedTab.setAttribute("isPageLocked", "true");
}
},
/* enable or disable page lock filter */
enableFilter: function(penable) {
var r = this.removeFilterListener;
if (penable) {
gBrowser.addTabsProgressListener(this.newPageListener);
window.addEventListener("unload", r, false);
} else {
this.removeFilterListener();
window.removeEventListener("unload", r, false);
}
},
/* remove pagelock filter listener */
removeFilterListener: function() {
gBrowser.removeTabsProgressListener(this.newPageListener);
},
/* new page loading listener */
newPageListener: {
onLocationChange: function(aBrowser, aWebProgress, aRequest, aLocationURI) {
var newurl = aLocationURI.spec;
if (newurl.indexOf("://") < 0) return;
var s = stmM.gPrefs.getComplexValue("pagelock.filterlist", Components.interfaces.nsISupportsString).data;
var list = (s ? s.split(" ") : "");
var finded = false;
for (var i = 0; i < list.length; i++) {
var item = list[i].split("\b");
if (item.length == 1) { //enabled
if (item[0] == newurl) { finded = true; break; }
}
}
var wtab = gBrowser.mTabs[gBrowser.getBrowserIndexForDocument(aBrowser.contentDocument)];
if (finded) wtab.setAttribute("isPageLocked", "true");
else wtab.removeAttribute("isPageLocked");
},
onStateChange: function(aWebProgress, aRequest, aFlag, aStatus) { },
onProgressChange: function(aWebProgress, aRequest, curSelf, maxSelf, curTot, maxTot) { },
onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage) { },
onSecurityChange: function(aWebProgress, aRequest, aState) { }
},
/* enable block */
enableBlock: function(penable) {
if (penable) {
this.enableBlockHotKey(true);
this.showBlockTabMenu(this.gPrefs.getBoolPref("block.showTabMenu"));
this.showBlockStatusbarMenu(this.gPrefs.getBoolPref("block.showStatusbarMenu"));
} else {
this.enableBlockHotKey(false);
this.showBlockTabMenu(false);
this.showBlockStatusbarMenu(false);
if (this.gBlockingOn) this.disableBlockObserver();
}
},
enableBlockHotKey: function(penable) {
var e = document.getElementById("k.block");
if (penable)
e.setAttribute("disabled", false);
else
e.setAttribute("disabled", true);
},
stopOnTabSwitch: function(penable) {
var c = gBrowser.tabContainer;
var f = this.disableBlockObserver;
if (penable)
c.addEventListener("TabSelect", f, false);
else
c.removeEventListener("TabSelect", f, false);
},
/* show/hide tab context block menu */
showBlockTabMenu: function(penable) {
for (var i=0; i<=2; i++)
document.getElementById("stm.tabBlockScope" + i).setAttribute("hidden", !penable);
document.getElementById("stm.tmSepa2").setAttribute("hidden", !penable);
document.getElementById("stm.tabBlockStopOnTabSwitch").setAttribute("hidden", !penable);
document.getElementById("stm.tmSepa1").setAttribute("hidden", !penable);
},
showBlockStatusbarMenu: function(penable) {
document.getElementById("stm.blockOption").setAttribute("hidden", !penable);
document.getElementById("stm.smSepa2").setAttribute("hidden", !penable);
for (var i=0; i<=2; i++) document.getElementById("stm.blockScope" + i).setAttribute("hidden", !penable);
document.getElementById("stm.smSepa1").setAttribute("hidden", !penable);
if (penable) {
document.getElementById("stm.blockOption").setAttribute("checked", this.gPrefs.getBoolPref("block.stopOnTabSwitch"));
for (var i=0; i<=2; i++) {
document.getElementById("stm.blockScope" + i).setAttribute("checked", (this.gPrefs.getIntPref("block.blockScope") == i && this.gBlockingOn));
}
}
},
blockObserver: {
observe: function(aSubject, aTopic, aData) {
aSubject.QueryInterface(Components.interfaces.nsIHttpChannel);
var url = aSubject.URI.spec;
var aBrowser = this.getBrowserfromDOM(aSubject, aSubject);
if (stmM.gPrefs.getBoolPref("block.stopOnTabSwitch")) {
if (this.noCancel(url, aSubject.URI.host, gBrowser.currentURI.host)) return; //request is in scope, do not block
if (!aBrowser || aBrowser != gBrowser.selectedBrowser) return;
} else {
for (var i = 0; i < gBrowser.browsers.length; i++) {
if (this.noCancel(url, aSubject.URI.host, gBrowser.getBrowserAtIndex(i).currentURI.host)) return;
}
if (!aBrowser || !aBrowser.contentTitle) return; //new tab first request has no contentTitle
}
aSubject.cancel(Components.results.NS_ERROR_FAILURE);
},
noCancel: function(url, httphost, chost) {
switch(stmM.gPrefs.getIntPref("block.blockScope")) {
case 0: //not host
if (httphost == chost) return true;
break;
case 1: //pics
if (!this.isType(url, 1)) return true;
break;
case 2: //music
if (!this.isType(url, 2)) return true;
break;
}
return false;
},
isType: function(url, type) {
var exts;
if (type == 1)
exts = new Array("js", "gif", "jpg", "jpeg", "png", "swf", "svg", "bmp");
else if (type == 2)
exts = new Array("mp3", "wma", "wav", "rm", "asf", "avi", "mpg", "mpeg", "mid", "wmv", "asx", "ra", "ram");
for (var i in exts) {
if (url.toLowerCase().indexOf("." + exts[i]) > -1)
return true;
}
return false;
},
getBrowserfromDOM: function(aChannel, aSubject) {
try {
var notificationCallbacks = aChannel.notificationCallbacks ? aChannel.notificationCallbacks : aSubject.loadGroup.notificationCallbacks;
if (!notificationCallbacks) return null;
var callback = notificationCallbacks.getInterface(Components.interfaces.nsIDOMWindow);
return callback.top.document ? gBrowser.getBrowserForDocument(callback.top.document) : null;
}
catch(e) { dump(e + "\n"); return null; }
},
},
toggleBlock: function() {
gBrowser.selectedBrowser.stop();
if (!this.gBlockingOn)
this.enableBlockObserver();
else
this.disableBlockObserver();
gBrowser.selectedBrowser.reloadWithFlags(Components.interfaces.nsIRequest.LOAD_NORMAL);
},
enableBlockObserver: function() {
Components.classes['@mozilla.org/observer-service;1'].getService(Components.interfaces.nsIObserverService).addObserver(this.blockObserver, 'http-on-modify-request', false);
if (this.gPrefs.getBoolPref("block.stopOnTabSwitch"))
gBrowser.tabContainer.addEventListener("TabSelect", this.disableBlockObserver, false);
this.gBlockingOn = true;
document.getElementById("stm.statuspanel").image="chrome://supertabmode/skin/stmbar162.png";
},
disableBlockObserver: function() {
Components.classes['@mozilla.org/observer-service;1'].getService(Components.interfaces.nsIObserverService).removeObserver(stmM.blockObserver, 'http-on-modify-request', false);
gBrowser.tabContainer.removeEventListener("TabSelect", stmM.disableBlockObserver, false);
stmM.gBlockingOn = false;
document.getElementById("stm.statuspanel").image="chrome://supertabmode/skin/stmbar16.png";
},
toggleBlockType: function(ptype) {
if (ptype == 9) {
this.gPrefs.setBoolPref("block.stopOnTabSwitch", !this.gPrefs.getBoolPref("block.stopOnTabSwitch"));
return;
}
gBrowser.selectedBrowser.stop();
if (this.gBlockingOn && ptype == this.gPrefs.getIntPref("block.blockScope"))
this.disableBlockObserver();
else{
this.gPrefs.setIntPref("block.blockScope", ptype);
if (!this.gBlockingOn) this.enableBlockObserver();
}
gBrowser.selectedBrowser.reloadWithFlags(Components.interfaces.nsIRequest.LOAD_NORMAL);
},
enableBosskey: function(penable) {
var e = document.getElementById("k.hideFF");
if (penable)
e.setAttribute("disabled", false);
else
e.setAttribute("disabled", true);
},
hideFirefox: function() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
obj = Components.classes["@supertabmode.mozdev.org/supertabmode;1"].getService(Components.interfaces.IStmBossKey);
var hotkey = this.gPrefs.getCharPref("bosskey.showkey");
var list = hotkey.split("|:|")[1].split("[+]");
var mod = "";
list[1].indexOf("control") >= 0 ? mod = mod + "1": mod = mod + "0";
list[1].indexOf("shift" ) >= 0 ? mod = mod + "1": mod = mod + "0";
list[1].indexOf("alt" ) >= 0 ? mod = mod + "1": mod = mod + "0";
list[1].indexOf("meta" ) >= 0 ? mod = mod + "1": mod = mod + "0";
var sb = document.getElementById("stm.stringmanager");
obj.hideFirefox(mod, list[0], this.gPrefs.getBoolPref("bosskey.minimizeToTray"),
sb.getString("bosskey.tooltip"), sb.getString("bosskey.restore"), sb.getString("bosskey.exit"));
},
minimizeToSysTray: function(winloaded, penable) {
if (!winloaded && !penable) return;
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
obj = Components.classes["@supertabmode.mozdev.org/supertabmode;1"].getService(Components.interfaces.IStmBossKey);
var sb = document.getElementById("stm.stringmanager");
obj.enableSysTray(penable, sb.getString("bosskey.tooltip"), sb.getString("bosskey.restore"), sb.getString("bosskey.exit"));
},
} //var end
window.addEventListener("load", function(e) { stmM.onLoad(); }, false);
window.addEventListener("unload", function(e) { stmM.onUnLoad(); }, false);